﻿//Todesesser Advanced Flash Game
//Copyright (C) 2009 Dean Gardiner
//
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.
package com.winmastergames.multiplayer 
{
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.ui.Keyboard;
	public class multiplayerChat extends MovieClip
	{	
		private var inputKeyDown:Boolean = false;
		public function multiplayerChat(stage:Stage) 
		{
			trace("MultiplayerChat Created!");
			stage.addChild(this);
			x = 0;
			y = stage.stageHeight;
			input.addEventListener(KeyboardEvent.KEY_DOWN, inputBox_KeyPress);
			input.addEventListener(KeyboardEvent.KEY_DOWN, inputBox_KeyUp);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_KeyPress);
			messages.text = "";
			input.text = "";
		}
		private function stage_KeyPress(e:KeyboardEvent)
		{
			if (e.keyCode == 13 && inputKeyDown == false)
			{
				input.visible = true;
				inputBoxParts.visible = true;
			}
		}
		private function inputBox_KeyUp(e:KeyboardEvent)
		{
			if (e.keyCode == 13)
			{
				trace("InputBox KeyUp: " + e.keyCode.toString());
				//input.visible = false;
				//inputBoxParts.visible = false;
				inputKeyDown = false;
			}
		}
		private function inputBox_KeyPress(e:KeyboardEvent)
		{
			if (e.keyCode == 13)
			{
				trace("InputBox KeyDown: " + e.keyCode.toString());
				sendMessage(input.text);
				inputKeyDown = true;
			}
		}
		public function sendMessage(msg:String)
		{
			messages.appendText("[ME]: " + msg + "\n");
		}
	}

}